import pprint

# python-stix
from stix.core import STIXPackage
import cybox.objects
from cybox.objects.address_object import Address
from cybox.objects.file_object import File
from stix.common.vocabs import IndicatorType
import traceback
import warnings


warnings.filterwarnings("ignore")

soxml='30EBBCAE4627CBB02705430EADA8209B7A639534_so.stix'

# Parse input file


# print all
# pprint.pprint(stix.to_dict()
# print all 2
# for i in stix.walk():
#     print i

url='URL Watchlist'
fileh='File Hash Watchlist'
domain='Domain Watchlist'
delimiter='##comma##'

def parseV(value):
    for i in value.split(delimiter):
        print i

# stix = STIXPackage.from_xml(soxml)
# obj = stix.to_obj()
try:
    package = STIXPackage.from_xml(soxml)
except:
    print traceback.format_exc()

for indicator in package.indicators:

    # Watchlist = i.get_Type()[0].get_valueOf_()

    print str(indicator.indicator_types[0])
    properties = indicator.observable.object_.properties
    if isinstance(properties,cybox.objects.uri_object.URI):
        print 'uri found ...'
        print 'xxxxxxxx',properties.value.condition
        print 'stxxxxxxxx',properties.value.value
    if isinstance(properties,Address):
        print 'address found ...'
        address_value = properties.address_value.value
        print address_value
    if isinstance(properties,File):
        print 'hash found ...'
        hash_value = [h.simple_hash_value.value for h in properties.hashes]
        print hash_value
    # print Watchlist
    # if Watchlist == url:
    #     print i.Observable.Object.Properties.Value.condition
    #     parseV(i.Observable.Object.Properties.Value.valueOf_)
    # elif Watchlist == fileh:
    #     for j in i.Observable.Object.Properties.Hashes.get_Hash():
    #         print j.Simple_Hash_Value.condition
    #         parseV(j.Simple_Hash_Value.valueOf_)
    # elif Watchlist == domain:
    #     print i.Observable.Object.Properties.get_Value().condition
    #     parseV(i.Observable.Object.Properties.get_Value().valueOf_)
    # else:
    #     print i.Observable.Object.Properties.Address_Value.condition
    #     parseV(i.Observable.Object.Properties.Address_Value.valueOf_)
# i=a.Indicators.get_Indicator()[0]
# i.Observable.Object.Properties.Address_Value.condition
# i.Observable.Object.Properties.Address_Value.valueOf_
